<?php

declare(strict_types=1);

namespace Api\Service\v1\Work;

use App\CustHub\Service\OpenWorkService;
use function Hyperf\Collection\data_get;

class ExternalContactApiService
{
    /**
     * 获取客户列表
     * @param array $params
     * @return mixed
     */
    public function getExternalContactList(array $params)
    {
        $service = make(OpenWorkService::class,[$params['corp_id']]);
        //获取部门列表
        $deptList = $service->getExternalContactList($params['userid']);
        return $deptList;
    }

    public function getExternalContactDetail(array $params)
    {
        $service = make(OpenWorkService::class,[$params['corp_id']]);
        $next_cursor = data_get($params,'next_cursor','');
        return $service->getExternalContactDetail($params['userid'],$next_cursor);
    }

    /**
     * 批量获取客户详情
     * @param array $params
     * @return array
     */
    public function batchGetExternalContactDetail(array $params): array
    {
        $service = make(OpenWorkService::class,[$params['corp_id']]);

        $limit = data_get($params,'limit',100);
        $cursor = data_get($params,'cursor','');

        $details = $service->batchGetExternalContactDetail($params['useridList'],$limit,$cursor);
        return $details;
    }


    /**
     * 获取客户群列表
     * @param array $params
     * @return array
     */
    public function getExternalContactGroupChatList(array $params): array
    {
        $service = make(OpenWorkService::class,[$params['corp_id']]);
        return $service->getExternalContactGroupChatList($params['userid'],$params['status_filter'],$params['cursor'],$params['limit']);
    }

    /**
     * 获取客户群详情
     * @param array $params
     * @return array
     */
    public function getExternalContactGroupChatDetail(array $params): array
    {
        $service = make(OpenWorkService::class,[$params['corp_id']]);
        return $service->getExternalContactGroupChatDetail($params['chat_id'],$params['need_name']);
    }

    public function modifyExternalContactInfo(array $data)
    {
        $service = make(OpenWorkService::class,[$data['corp_id']]);
        $modifyData = [
            'userid' => $data['userid'],
            'external_userid' => $data['external_userid'],
        ];

        if (!empty($data['remark'])) {
            $modifyData['remark'] = $data['remark'];
        }

        if (!empty($data['description'])) {
            $modifyData['description'] = $data['description'];
        }

        if (!empty($data['remark_company'])) {
            $modifyData['remark_company'] = $data['remark_company'];
        }

        if (!empty($data['remark_mobiles'])) {
            $modifyData['remark_mobiles'] = $data['remark_mobiles'];
        }
        return $service->modifyExternalContactInfo($modifyData);
    }

    public function markTag(array $data)
    {
        $service = make(OpenWorkService::class,[$data['corp_id']]);
        return $service->markTag($data['userid'],$data['external_userid'],$data['add_tag'],$data['remove_tag']);
    }
}